import * as bm from "/js/baseModule.js";

export class Module extends bm.baseModule {
    constructor(view) {
        super(view);
        let vueDom = this.find("#LoginForm_vue").get(0);
        let user = globalData.user;
        this.LoginForm_vue = new Vue({
            el: vueDom,
            data: globalData,
            watch: {
                'user.phone': "checkInfo",
            }
        });
        $(document).on("data_update",function () {
            if(globalData.user.user_type == 100){
                window.location.hash = 'index';
            }
        });
        if(globalData.user.user_type == 100){
            window.location.hash = 'index';
        }
    }

    //正则检测手机号
    _checkPhone(phone) {
        if (!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(phone))) {
            return false;
        }
        return true;
    }

    //提交表单
    _evt_submitForm() {
        let that = this;
        //得有一个接口去验证手机号是不是工程商
        if (that._checkPhone(that.LoginForm_vue.user.mobile)) {
            api.getInfoByMobile(that.LoginForm_vue.user.mobile, {
                succ: function (json) {
                    let userInfo = json.user;
                    if (userInfo) {
                        globalData.user.user_type = userInfo.type;
                    }

                }
            });
            location.hash = 'login/Code';

        } else {
            funs.tip('手机号不正确', '请确认您的手机号是否输入正确', 'fail', 2000);
        }
    }
}
